<html>
<head><meta charset="utf-8"><title>Why `&amp;fn()` of two different functions are the same? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html">Why `&amp;fn()` of two different functions are the same?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206261968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206261968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206261968">(Aug 07 2020 at 14:17)</a>:</h4>
<p>I discovered this when trying to print fn address, issue at <a href="https://github.com/rust-lang/rust/issues/75239">#75239</a><br>
<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=0b9f2e9d8623576f54350c09d41bf8d6">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=0b9f2e9d8623576f54350c09d41bf8d6</a></p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="mi">42</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">16</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:p}&quot;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">Left</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:p}&quot;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>stdout:</p>
<div class="codehilite"><pre><span></span><code>0x565408422000
0x565408422000
</code></pre></div>


<p>Is this behaviour expected and documented elsewhere?<br>
cc <span class="user-mention" data-user-id="120791">@RalfJ</span> <span class="user-mention" data-user-id="124288">@oli</span></p>



<a name="206262223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262223">(Aug 07 2020 at 14:19)</a>:</h4>
<p>it's not guarenteed to be stable AFAIK</p>



<a name="206262287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262287">(Aug 07 2020 at 14:19)</a>:</h4>
<p>llvm sometimes deduplicates functions if they are the same</p>



<a name="206262290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262290">(Aug 07 2020 at 14:19)</a>:</h4>
<p>it's the address of a local variable, though in this case it looks like it might be promoted?</p>



<a name="206262340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262340">(Aug 07 2020 at 14:20)</a>:</h4>
<p>i think there is an open issue somewhere</p>



<a name="206262381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262381">(Aug 07 2020 at 14:20)</a>:</h4>
<p>note that in this case they'd have different return values, and this is <em>not</em> printing the address of the function</p>



<a name="206262445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262445">(Aug 07 2020 at 14:21)</a>:</h4>
<p>oh, I misread</p>



<a name="206262491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262491">(Aug 07 2020 at 14:21)</a>:</h4>
<p>both <code>bar</code> and <code>size_of::&lt;Left&gt;</code> are ZST</p>



<a name="206262510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262510">(Aug 07 2020 at 14:21)</a>:</h4>
<p>so the pointers just point into the void <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="206262516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262516">(Aug 07 2020 at 14:21)</a>:</h4>
<p>maybe that's it...</p>



<a name="206262915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262915">(Aug 07 2020 at 14:24)</a>:</h4>
<p>if so, is <code>&amp;fn</code> actually useful?</p>



<a name="206262950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262950">(Aug 07 2020 at 14:25)</a>:</h4>
<p>you need <code>&amp;fn as *const ()</code></p>



<a name="206262964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262964">(Aug 07 2020 at 14:25)</a>:</h4>
<p>er, no</p>



<a name="206262980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206262980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206262980">(Aug 07 2020 at 14:25)</a>:</h4>
<p>you want <code>fn as *const () as usize</code> or so</p>



<a name="206263009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263009">(Aug 07 2020 at 14:25)</a>:</h4>
<p><a href="https://gitlab.com/YottaDB/Lang/YDBRust/-/blob/master/src/simple_api/mod.rs#L1866">https://gitlab.com/YottaDB/Lang/YDBRust/-/blob/master/src/simple_api/mod.rs#L1866</a></p>



<a name="206263029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263029">(Aug 07 2020 at 14:25)</a>:</h4>
<p>yeah, what <span class="user-mention silent" data-user-id="116122">simulacrum</span> said</p>



<a name="206263162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263162">(Aug 07 2020 at 14:26)</a>:</h4>
<p>if <code>&amp;fn</code> is not useful, does it make sense to make a lint about using it?</p>



<a name="206263245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263245">(Aug 07 2020 at 14:27)</a>:</h4>
<p>I think that's a great idea</p>



<a name="206263318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263318">(Aug 07 2020 at 14:28)</a>:</h4>
<p>hm well that's not quite true</p>



<a name="206263336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263336">(Aug 07 2020 at 14:28)</a>:</h4>
<p>there are times when you want a pointer to a pointer</p>



<a name="206263363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263363">(Aug 07 2020 at 14:28)</a>:</h4>
<p>e.g., if you want <code>dyn Fn()</code> from a function pointer</p>



<a name="206263384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206263384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206263384">(Aug 07 2020 at 14:28)</a>:</h4>
<p>in any case I'd start with a clippy lint</p>



<a name="206264540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206264540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206264540">(Aug 07 2020 at 14:37)</a>:</h4>
<p>I think the lint should be about using pointers to a ZST</p>



<a name="206264611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206264611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206264611">(Aug 07 2020 at 14:38)</a>:</h4>
<p>well, I guess that's not quite right since <code>*const ()</code> is also a ZST ... maybe about using pointers to function items instead of function pointers?</p>



<a name="206264731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206264731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206264731">(Aug 07 2020 at 14:39)</a>:</h4>
<p>I've never really understood why functions decay to pointers to function items instead of function pointers</p>



<a name="206264810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206264810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206264810">(Aug 07 2020 at 14:39)</a>:</h4>
<p>hm?</p>



<a name="206264826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206264826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206264826">(Aug 07 2020 at 14:40)</a>:</h4>
<p>what do you mean pointers to function items?</p>



<a name="206264987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206264987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206264987">(Aug 07 2020 at 14:41)</a>:</h4>
<p>if you use <code>f</code> in an expression context, it will not have a meaningful address</p>



<a name="206265010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265010">(Aug 07 2020 at 14:41)</a>:</h4>
<p>e.g. the transmute in the link I posted</p>



<a name="206265023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265023">(Aug 07 2020 at 14:41)</a>:</h4>
<p>you need to use <code>f as *const ()</code> for it to be useful</p>



<a name="206265060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265060">(Aug 07 2020 at 14:41)</a>:</h4>
<p><a href="https://doc.rust-lang.org/reference/types/function-item.html#function-item-types">https://doc.rust-lang.org/reference/types/function-item.html#function-item-types</a></p>



<a name="206265061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265061">(Aug 07 2020 at 14:41)</a>:</h4>
<p>er, right, because functions have a unique type (which is actually good)</p>



<a name="206265148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265148">(Aug 07 2020 at 14:42)</a>:</h4>
<p>you want that for things like <code>[].iter().map(std::convert::identity)</code> to not need to de-virtualize</p>



<a name="206265297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265297">(Aug 07 2020 at 14:43)</a>:</h4>
<p>I think using it in a context that doesn't expect <code>Fn</code> should be a lint, then</p>



<a name="206265333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265333">(Aug 07 2020 at 14:44)</a>:</h4>
<p>e.g. <code>map(f)</code> is fine, but <code>transmute(f)</code> or <code>f == f</code>should be a lint</p>



<a name="206265382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265382">(Aug 07 2020 at 14:44)</a>:</h4>
<p>hm well, perhaps</p>



<a name="206265403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265403">(Aug 07 2020 at 14:44)</a>:</h4>
<p>though... I would expect it to not compile in almost all other contexts?</p>



<a name="206265441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265441">(Aug 07 2020 at 14:44)</a>:</h4>
<p>well clearly it does <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> hence <span class="user-mention" data-user-id="209117">@lzutao</span> posted his question</p>



<a name="206265479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265479">(Aug 07 2020 at 14:45)</a>:</h4>
<p>That code sample doesn't do anything but take a reference though</p>



<a name="206265495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265495">(Aug 07 2020 at 14:45)</a>:</h4>
<p>and we can't know what you're going to do with that reference</p>



<a name="206265564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265564">(Aug 07 2020 at 14:46)</a>:</h4>
<p>clippy could walk the HIR, couldn't it?</p>



<a name="206265614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265614">(Aug 07 2020 at 14:46)</a>:</h4>
<p>I'd expect this to be a clippy lint, not in rustc itself</p>



<a name="206265626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265626">(Aug 07 2020 at 14:46)</a>:</h4>
<p>I mean <em>maybe</em> but it'd be hard</p>



<a name="206265673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265673">(Aug 07 2020 at 14:46)</a>:</h4>
<p>or at least it feels hard :)</p>



<a name="206265916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206265916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206265916">(Aug 07 2020 at 14:48)</a>:</h4>
<p>well, fair enough :P but I think it would be worthwhile, that 6 line comment came about because I spent an hour debugging a segfault</p>



<a name="206266036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266036">(Aug 07 2020 at 14:49)</a>:</h4>
<p>I mean that's sort of on you in some sense when you write unsafe code, and don't verify what you're taking a pointer to :)</p>



<a name="206266040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266040">(Aug 07 2020 at 14:49)</a>:</h4>
<p>but you're not wrong</p>



<a name="206266171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266171">(Aug 07 2020 at 14:50)</a>:</h4>
<p>it might be interesting to special-case converting a &amp;T where T is a ZST to a <code>*const</code> as a warning, though it would need to be post-monomorphization which is not great.</p>



<a name="206266253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266253">(Aug 07 2020 at 14:51)</a>:</h4>
<p>I don't know that there needs to be a change in behavior, that seems much more risky haha</p>



<a name="206266276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266276">(Aug 07 2020 at 14:51)</a>:</h4>
<p>but a lint 'this doesn't do what you think it does' would have been <em>very</em> helpful</p>



<a name="206266303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266303">(Aug 07 2020 at 14:51)</a>:</h4>
<p>I didn't say anything about behavior change?</p>



<a name="206266330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206266330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206266330">(Aug 07 2020 at 14:51)</a>:</h4>
<p>oh oh I misread</p>



<a name="206336780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206336780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206336780">(Aug 08 2020 at 07:34)</a>:</h4>
<p>beyond the fact that <code>&amp;fn()</code> is a ptr-to-ptr, it is also the case that different functions can have the same address and the same function can have different addresses. see e.g. <a href="https://github.com/rust-lang/rust/issues/54685">https://github.com/rust-lang/rust/issues/54685</a>, <a href="https://github.com/rust-lang/rust/issues/70861">https://github.com/rust-lang/rust/issues/70861</a>.</p>



<a name="206342258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206342258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206342258">(Aug 08 2020 at 10:30)</a>:</h4>
<p>Off-topic: according to <a href="https://doc.rust-lang.org/nightly/std/primitive.fn.html">https://doc.rust-lang.org/nightly/std/primitive.fn.html</a> , <code>fn() -&gt; usize</code> also implements <code>fmt::Pointer</code> trait.<br>
Why I cannot print it with <code>{:p}</code> format directly but having to cast to <code>*const ()</code> ?<br>
if I cannot, what does Pointer do ?</p>



<a name="206342790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206342790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206342790">(Aug 08 2020 at 10:48)</a>:</h4>
<p>Are you sure you tried to print a function pointer (<code>fn()</code>) and not a function item (<code>fn() { function_name }</code>)? Did you explicitly cast it to a function pointer? (<code>println!("{:p}", function_name as fn());</code>)</p>



<a name="206342818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206342818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206342818">(Aug 08 2020 at 10:49)</a>:</h4>
<p>You always get exactly one chance for an implicit coercion to happen. If rustc didn't think it was necessary at that point, it won't ever try again.</p>



<a name="206343849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206343849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206343849">(Aug 08 2020 at 11:20)</a>:</h4>
<p>I'm confused. If <code>bar</code> is a function item, is <code>&amp;bar</code> a function pointer/reference?</p>



<a name="206344082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206344082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206344082">(Aug 08 2020 at 11:28)</a>:</h4>
<p><code>&amp;bar</code> should be a reference to a function item</p>



<a name="206344085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206344085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206344085">(Aug 08 2020 at 11:28)</a>:</h4>
<p>so a reference to a ZST</p>



<a name="206344093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206344093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206344093">(Aug 08 2020 at 11:28)</a>:</h4>
<p>unless coercion happens, in which case <code>&amp;bar</code> is a reference to a function pointer afaik</p>



<a name="206344572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206344572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206344572">(Aug 08 2020 at 11:45)</a>:</h4>
<p>Thank you. I got it. Although I expect most people would fall in the same trap like me.<br>
Or at least all C/C++ developers would expect <code>bar</code> to be a function pointer.<br>
I don't blame anyone. It is just confusing. The compiler and the book seems like not helping to explain things.</p>



<a name="206391620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206391620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206391620">(Aug 09 2020 at 11:48)</a>:</h4>
<p>Yeah it is confusing. the expression <code>bar</code> is a "singleton type", a ZST, representing the particular function <code>bar</code>. that singleton type coerces to a function pointer.</p>



<a name="206391626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20%60%26fn%28%29%60%20of%20two%20different%20functions%20are%20the%20same%3F/near/206391626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20.60.26fn().60.20of.20two.20different.20functions.20are.20the.20same.3F.html#206391626">(Aug 09 2020 at 11:48)</a>:</h4>
<p>feel free to submit PRs or report issues if you find concrete places that you think could explain this better :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>